// lib/redisClient.ts
import Redis from 'ioredis';

declare global {
  // eslint-disable-next-line no-var
  var redis: Redis | undefined;
}

let redis: Redis;

if (!global.redis) {
  if (process.env.REDIS_URL) {
    global.redis = new Redis(process.env.REDIS_URL);
  } else {
    throw new Error('REDIS_URL is not defined');
  }
}

redis = global.redis;

export default redis;

